/* ************************************************************************************************

	Copyright (c) 2005-2006, IGR
	All Rights Reserved.
	Licensed under the Apache License version 2.0 or above.
	For more information on licensing, see:
        http://www.apache.org/licenses/


************************************************************************************************
 Objet type BUTTON
 VERSION:0.85
 DATE:16/03/2006
************************************************************************************************
 Init parameter in objPar (object of parameter):
  Name:              Button name
  top:           	 Top position (in pixel)
  left:              Left position (in pixel)    
  title				 text of the button
  alt				 tooltip message
  parent:            button parent
************************************************************************************************/

rialto.widget.Button=function(top,left,title,alt,parent,objPar){
//=============

    var src1="bigButtonOff";        
    var src2="bigButtonOn";
            
   
    //base constructor
    objParam={};
    objParam.type="button";
    objParam.top=top;
    objParam.left=left;
    this.base = rialto.widget.AbstractComponent;  
    this.base(objParam);
    
    //Default value
    this.title = title;
    this.enable=true;
    this.alt=alt?alt:title;
    //Propertie
	//set the value with the properties of the objPar object       
   	if (objPar != null){               
        if (rialto.lang.isBoolean(objPar.enable)){
            this.enable = objPar.enable;
        }               
    }
	//release object	
	objParam=null;
	objPar=null;
	this.base=null;
	var oThis=this;    
    
    // *******************************************
	// GENERATION OF DOM ELEMENTS
	// *******************************************
	
	//Size of the text
	this.textSize=Math.max(getTailleTexte(this.title,"textButton")+13,88);
	this.divExt.style.height="18px";
	this.divExt.style.top=this.top;
	this.divExt.style.left=this.left;
	this.divExt.className="test";
	this.divExt.style.position=this.position;
    this.divExt.style.width=this.textSize;
   	this.divExt.title=this.alt;
	
	//Construction of the button
    //left image
    this.imgG=document.createElement("DIV")
    this.imgG.className="leftEdgeButtonOff";
    
    //text and his shadow
    this.divCenter=document.createElement("DIV")
    this.divCenter.className="centerButtonOff";
    this.divCenter.style.width=this.textSize-8;
    this._divTitle=document.createElement("DIV")
    this._divTitle.className="textButton";
    this._divTitle.innerHTML=this.title;

    this._divTitleShadow=document.createElement("DIV");
    this._divTitleShadow.className="shadowTextButton";   
    this._divTitleShadow.innerHTML=this.title;

    
    //right image    
    this.imgD=document.createElement("DIV")
    this.imgD.className="rightEdgeButtonOff";    

    this.divExt.appendChild(this.imgG);
    this.divExt.appendChild(this.divCenter);
    this.divCenter.appendChild(this._divTitleShadow);
    this.divCenter.appendChild(this._divTitle);
    this.divExt.appendChild(this.imgD);
     
    //EVENT
    this.divExt.onmouseout = function(e){                                               
	    if (oThis.enable){
	        if (!e) e=window.event;
	        oThis.switchImage("Off");	
   	    	this.style.cursor='default';		
	        oThis.onmouseout(e);                    
	    }
	}; 	        

    this.divExt.onmouseover = function(e){                        
        if (oThis.enable){
        	if (!e) e=window.event;                               
	    	oThis.switchImage("On");
	    	this.style.cursor='pointer';
	        //call the applicative method
	        oThis.onmouseover();
	    }
    };  

    this.divExt.onclick = function(e){
        if (!e) e=window.event;
        if (oThis.enable){   
            oThis.onclick(e);                
            stopEvent(e);
        }
    };

    if(!this.enable){this.setEnable(this.enable);}
    
    //add to the parent
    if (parent) {this.placeIn(parent);}; 
    
    }

//********   super *************

rialto.widget.Button.prototype = new rialto.widget.AbstractComponent;


rialto.widget.Button.prototype.switchImage=function(status) {
	this.imgG.className="leftEdgeButton"+status;    
    //text and his shadow
    this.divCenter.className="centerButton"+status;    
    //right image    
    this.imgD.className="rightEdgeButton"+status;  	
}

//********  public methods *********

//2 METHODS ARE DEPRECATED...USE SETENABLE

rialto.widget.Button.prototype.inactive=function() {
   rialto.deprecated('Button','inactive','setEnable(false)');
   this.setEnable(false); 
}

rialto.widget.Button.prototype.active=function() {
   rialto.deprecated('Button','active','setEnable(true)');
   this.setEnable(true);
}


//this method will allow to enable or disable the button according to the parameter
rialto.widget.Button.prototype.setEnable=function(enable){
	if(enable){
		this._divTitleShadow.style.display='block';
		this._divTitle.className="textButton";
		this.switchImage("Off");
	}
	else{
		this._divTitleShadow.style.display='none';
		this._divTitle.className="textButtonDisa";
		this.switchImage("Disa");
	}
	this.enable=enable;
}

//this method will allow to change the text in the button
rialto.widget.Button.prototype.setTitle =function(title){
//================================
	if(this.alt=this.title){this.alt=title};
	this.title=title;
	this._divTitleShadow.innerHTML=title;
	this._divTitle.innerHTML=title;
    
}

rialto.widget.Button.prototype.release=function(){
    this.divExt.onmouseout = null;
    this.divExt.onmouseover = null;
    this.divExt.onclick = null;    
}
